#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "wallyingLib.h"


static uint8_t data_buf[10] = {0x00};
static uint32_t data_len = 0;

static void byte_bits_show(char *name, uint8_t *data, uint32_t len)
{
	printf("%s [len = %d] :\r\n", name, len);
	for (int j = 0; j < len; j++) {
		for (int i = 0; i < 8; i++) {
			if (bit_get(&data[j], i)) {
				printf("1 ");
			} else {
				printf("0 ");
			}
		}
		printf("  ");
	}
	printf("\r\n");
}

int main(int argc, char *argv[])
{
    printf("Hello World!\r\n");

	while (1)
	{
		memset(data_buf, 0, sizeof(data_buf));

		data_len = rand_number(1, 8);
		for (int i = 0; i < data_len; i++) {
			data_buf[i] = rand_number(0x00, 0xFF);
		}
		hexdump("data_buf", data_buf, data_len);
		byte_bits_show("data_buf", data_buf, data_len);

		bits_reverse(data_buf, data_len * 8);

		hexdump("data_buf -> bits_reverse", data_buf, data_len);
		byte_bits_show("data_buf -> bits_reverse", data_buf, data_len);

		system("pause");
	}

    system("pause");
    return 0;
}
